package com.suzus.seven;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.suzus.utils.RabbitMqUtils;

import java.nio.charset.StandardCharsets;

public class ReceiveLogsTopic {
    public static final String EXCHANGE_NAME="topic_logs";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC);
        channel.queueDeclare("Q1",false,false,false,null);
        channel.queueBind("Q1",EXCHANGE_NAME,"*.orange.*");
        System.out.println("waiting for information");

        DeliverCallback deliverCallback = (ConsumerTag, message)->{
            System.out.println(new String(message.getBody(), StandardCharsets.UTF_8)+" Q1 "+message.getEnvelope().getRoutingKey());
        };

        channel.basicConsume("Q1",true,deliverCallback,consumerTag->{});
    }
}
